<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

$(function(){
	//表格加载
	$('#receiveStatusTable').datagrid({
	    url:'<c:url value="/receive/receiveStatusDate" />',
	    queryParams:getParams(),//提交参数
	    
	    toolbar:'#receiveStatusToolbar',//表头工具栏
	   /* pagination:true,//显示分页  
	    pagePosition:'bottom',//分页栏出现位置
	    pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
*/	    singleSelect:true,
	    columns:[[
			{field:'docReceiverId',title:'序号',width:50,align:'center',formatter: function(value,row,index){
				return index+1;
			}},
			{field:'docReceiverOrgName',title:'接收单位',formatter: function(value,row,index){
				return row.docSendUuid?("<a style='text-decoration: none;' title='"+value+"' href=\"javascript:openDonePage('"+row.docSendUuid+"')\">"+value+"</a>"):value;
			}},
			{field:'docArrived',title:'接收情况',formatter: function(value,row,index){
				var docReceiveStat=row.docReceiveStat;
				if(value == 0){
                    return "<font color='red'>未送达</font>";
                } else if(value == 1 && docReceiveStat==0){
                	return "已送达";
                } else if(value == 1 && docReceiveStat==1){
                	return "已签收"+(row.docReceiveInfo==""||row.docReceiveInfo=="null"||row.docReceiveInfo==null?"":"(回执信息: "+row.docReceiveInfo+")");
				} else if(value == 1 && docReceiveStat==2){
					return "<font color='red'>已拒收</font>"+(row.docReceiveInfo==""||row.docReceiveInfo=="null"||row.docReceiveInfo==null?"":"(回执信息: "+row.docReceiveInfo+")");
				}else if(value == 1 && docReceiveStat==3){
					return "<font color='red'>已收回</font>";
				}else{
					return "发送失败"==row.docReceiveAddress || ("null"==row.docReceiveAddress || null==row.docReceiveAddress) && (null==row.docReceiverId || 'null'==row.docReceiverId)?("<font color='red'>发送失败</font>"):row.docReceiveAddress;
				}
			}},
			{field:'docArriveTime',align:'center',title:'送达时间',formatter: function(value,row,index){
				var str="";
				if(value){
					str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss");
				}
				return str;
			}},
			{field:'docCheckinTime',align:'center',title:'办理时间',formatter: function(value,row,index){
				var str="";
				if(value){
					str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss");
				}
				return str;
			}},
			{field:'docInfo',align:'center',hidden:"<c:out value='${handleFlag}' />"!="1",title:'操作',formatter: function(value,row,index){
				return row.docArrived==1&&row.docReceiveStat==0&&(row.docReceiverId!=null || row.docReceiverId!="null")?
						'<a href="javascript:void(0)" onclick="issueCalBack(\''+row.docReceiverId+'\')">发文收回</a>':'';
			}}
	    ]]
	});
});

//查询条件生成方法
function getParams(){
	var jsonObj=new Object();
	/*if($('input[name="formCategoryId"]').val()!=""){
		jsonObj.formCategoryId=$('input[name="formCategoryId"]').val();
	}*/
	jsonObj.issueId="<c:out value='${issueId}' />";
	return jsonObj;
}
function issueCalBack(docReceiverId){
	$.ajax({
		   type: "POST",
		   url: _documentContext+"/receive/receiveSingleBack",
		   data: "docReceiverId="+docReceiverId,
		   async: false,
		   success: function(msg){
		     if(msg.state!="200"){
		    	 $.messager.alert("提示","操作失败"); 
		     }
		     $('#receiveStatusTable').datagrid("reload",getParams());
		   }
		});
}
function openDonePage(issueId){
	var url=_synergyContext+"/basic/donePage?issueId="+issueId+"&backType=close"; 
	var winFeatures = "height="+(window.screen.height-80)+"px,width="+(window.screen.width-20)+"px,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no";
	window.open(url,'_blank',winFeatures);
}